﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using PersonaLibrary.PrintViewModel.Model;

namespace PersonaLibrary.Converters
{
	internal sealed class ColumnWidthConverter : IValueConverter
	{
		public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			Column column = parameter as Column;

			if(column == null)
				throw new ArgumentException("parametr must be Column type");

			if (value is bool)
			{
				if ((bool)value) return column.Width;
				else
					return new GridLength(0, GridUnitType.Star);
			}
			return null;
		}

		public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value is GridLength)
			{
				if (((GridLength)value).Value != 0) return true;
				else return false;
			}
			return null;
		}
	}
}
